package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Levelapplicationform;
import com.woniuxy.entity.Transaction;
import com.woniuxy.service.AgentLevelSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

import javax.servlet.http.HttpSession;

/**
 * Auther: Administrator  <br/>
 * Date: 2021/2/23:11:57  <br/>
 * Description:
 */
@RestController
@RequestMapping(value = "/agentLevelSetting")
public class AgentLevelSettingController {
    @Autowired
    private AgentLevelSettingService agentLevelSettingService;

    /**
     * Description : 用户查询自己提交的升级请求  <br/>
     * ChangeLog : 1. 创建 (2021/2/23 14:17 [Administrator]);
     * @param
     * @return void
     **/
    @RequestMapping(value = "/selectMyLevelApplicationform")
    public ResponseEntity<List<Levelapplicationform>> selectMyLevelApplicationform(@ApiIgnore HttpSession httpSession){
        List<Levelapplicationform> levelapplicationforms = agentLevelSettingService.selectMyLevelApplicationform(httpSession);
        ResponseEntity<List<Levelapplicationform>> Levelapplicationform=new ResponseEntity<>(levelapplicationforms);
        System.out.println("接收到前端的请求");
        return Levelapplicationform;
    }

    /**
     * Description : 用户查询自己旗下代理提交的升级请求  <br/>
     * ChangeLog : 1. 创建 (2021/2/24 15:17 [Administrator]);
     * @param httpSession
     * @return void
     **/
    @RequestMapping(value = "/selectOtherLevelApplicationform")
    public ResponseEntity<List<Levelapplicationform>> selectIOtherLevelApplicationform(@ApiIgnore HttpSession httpSession){
        List<Levelapplicationform> levelapplicationforms = agentLevelSettingService.selectOtherLevelApplicationform(httpSession);
        ResponseEntity<List<Levelapplicationform>> Levelapplicationform=new ResponseEntity<>(levelapplicationforms);
        return Levelapplicationform;
    }

    /**
     * Description : 用户提交代理请求  <br/>
     * ChangeLog : 1. 创建 (2021/2/24 15:22 [Administrator]);
     * @param levelapplicationform
     * @return void
     **/
    @RequestMapping(value = "/insertLevelApplicationform")
    public void insertLevelApplicationform(Levelapplicationform levelapplicationform ,@ApiIgnore HttpSession session){
        System.out.println(levelapplicationform);
        int row=agentLevelSettingService.insertLevelApplicationform(levelapplicationform,session);
    }

    /**
     * Description : 用户删除自己提交的代理请求  <br/>
     * ChangeLog : 1. 创建 (2021/2/24 15:23 [Administrator]);
     * @param id
     * @return String
     **/
    @RequestMapping(value = "/deleteLevelApplicationform")
    public String deleteLevelApplicationform(int id,@ApiIgnore HttpSession session){
        //为防止非法操作，校验提交的id是否为已经登录的账号的代理请求id
        List<Levelapplicationform> levelapplicationforms = agentLevelSettingService.selectMyLevelApplicationform(session);
        for (int i=0;i<levelapplicationforms.size();i++) {
            if (levelapplicationforms.get(i).getId()==id){
                int row=agentLevelSettingService.deleteLevelApplicationform(id);
                return "成功";
            }
        }
        return "失败";
    }

    /**
     * Description : 用户修改自己提交的代理请求  <br/>
     * ChangeLog : 1. 创建 (2021/2/24 15:48 [Administrator]);
     * @param levelapplicationform
     * @return void
     **/
    @RequestMapping(value = "/updateLevelApplicationform")
    public String updateLevelApplicationform(@RequestBody Levelapplicationform levelapplicationform,@ApiIgnore HttpSession session){
        //为防止非法操作，校验提交的id是否为已经登录的账号的代理请求id
        List<Levelapplicationform> levelapplicationforms = agentLevelSettingService.selectMyLevelApplicationform(session);
        for (int i=0;i<levelapplicationforms.size();i++) {
            if (levelapplicationforms.get(i).getId()==levelapplicationform.getId()){
                int row=agentLevelSettingService.updateLevelApplicationform(levelapplicationform);
                return "成功";
            }
        }
        return "失败";
    }
}
